Vue.component('myheader',{
    props: ["c_arr","search","user","kw"],
    template: `
        <header class="container">
    <!--导航条开始-->
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#">
                    <img alt="Brand" src="images/logo.png">
                </a>
            </div>
            <!--分类开始-->
            <ul class="nav navbar-nav">
                <li><a href="/">首页</a></li>
                <li v-for="c in c_arr">
                    <a :href="'/index.html?cid='+c.id">{{c.name}}</a>
                </li>

                <li>
                    <form action="">
                        <input type="text" placeholder="Search" v-model="kw">
                        <button type="button" @click="search()">
                            <i class="fa fa-search"></i>
                        </button>
                    </form>
                </li>
            </ul>
            <!--分类结束-->
            <ul class="nav navbar-nav navbar-right">
                <li v-if="user==''"><a href="/login.html" >管理员入口</a></li>
                <li v-if="user!=''"><a href="/admin.html">管理页面</a></li>
            </ul>
        </div>
    </nav>
    <!--导航条结束-->

</header>
    `
})
let header_vm =new Vue({
    el:"myheader",
    data:{
        c_arr:[],
        user:"",
        kw:""
    },
    created:function () {
        axios.get("/category/select").then(function (response) {

            header_vm.c_arr=response.data;
        })
        axios.get("/checkLogin").then(function (response) {
            header_vm.user=response.data;

        })
    },
    methods:{
        search:function () {
            //跳转到首页并且把搜索的关键字传递过去
            location.href="/index.html?kw="+header_vm.kw;

        }
    }
})